let api = {
    // 学生注册接口
    SaveStudent: '/student/saveSingle',
    // 获取学生信息
    GetStudent: '/student/querySingle',
    // 获取手机验证码
    GetVerification: '/student/getVerification',
    // 账号密码登录接口
    Login: '/student/login',
    // 修改面
    ForgetPassword: '/student/forget',
    // 手机验证码登录接口
    VerificationLogin: '/student/verificationLogin',
    // 绑定微信信息和手机号记录
    BindMobileAndUnionId: '/student/bindPhone',
    // 加入购物车
    SaveCar: '/car/saveSingle',
    //删除购物车
    DeleteCar: '/car/deleteSingle',
    // 填写订单页面
    OrderInfo: '/order/orderInfo',
    // 加载区域
    AreaList: '/area/queryList',
    AreaChild: '/area/queryChild',
    // 添加地址
    SaveAddress: '/address/saveSingle',
    // 修改地址
    UpdateAddress: '/address/updateSingle',
    // 删除地址
    DeleteAddress: '/address/deleteSingle',
    // 查询地址
    AddressSingle: '/address/querySingle',
    // 修改默认地址
    ChangeDefault: '/address/changeDefault',
    // 创建订单
    CreateOrder: '/order/createOrder',
    // 查看快递
    ExpressInfo: '/express/querySingle',
    // 删除订单
    DeleteOrder: '/order/deleteSingle',
    // 确认收货
    QueryReceipt: '/order/queryReceipt',
    ProductInfo: '/product/querySingle',
    // 退款
    Refund: '/pay/refund',
    // 消息推送
    PushMessage: '/push/sendBuy',
}

/**
 * 封装的统一请求接口
 * post请求，headers携带Token
 * @param param
 */
function post(url, param) {
    return new Promise(function (resolve, reject) { //返回Promise对象
        $.ajax({
            url: url,
            data: param,
            dataType: 'json',
            type: 'post',
            async: false,
            success: function (result) {
                resolve(result);
            },
            error: function (err) {
                reject(err);
            }
        });
    });
}


/**
 * 获取浏览器Cookie登录对象
 * @return {string|any}
 */
function getCookie(key) {
    let getCookie = document.cookie.replace(/[ ]/g, "")
    if (getCookie.length > 0) {
        let arrCookie = getCookie.split(';');
        for (let i = 0; i < arrCookie.length; i++) {
            let arr = arrCookie[i].split('='); //再次切割
            // token是字符串，并不是JSON字符串，所以直接返回
            if (arr[0] === 'token') {
                return arr[1]
            }
            if (arr[0] == key) {
                return JSON.parse(decodeURIComponent(arr[1]))
            }
        }
    }
}

/**
 * 存入Cookie
 * @param key
 */
function setCookie(key, studentEntity) {
    //设置名称为name,值为value的Cookie
    let expdate = new Date();   //初始化时间
    expdate.setTime(expdate.getTime() + 60 * 60 * 24 * 7);   //时间
    document.cookie = key + "=" + studentEntity + ";expires=" + expdate.toGMTString() + ";path=/";
}

